package com.opensicence.test.javafx;
	
import java.net.URL;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Main extends Application {
	@Override
	public void start(Stage primaryStage) {
		try {
			GridPane root = new GridPane();
			root.setAlignment(Pos.CENTER);//这句话什么意思？
			root.setHgap(10);
			root.setVgap(10);
			root.setPadding(new Insets(25, 25, 25, 25));
			
//			root.setGridLinesVisible(true);
			
			Text welcome = new Text();
			welcome.setText("Welcome");
			welcome.setId("welcome");
//			welcome.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
			root.add(welcome, 0, 0, 2, 1);
//			root.add(welcome, 0, 0);
			
			Label userName = new Label("User  Name:");
			root.add(userName, 0, 1);
			TextField userTextField = new TextField();
			root.add(userTextField, 1, 1);
			
			Label password = new Label("Password:");
			root.add(password, 0, 2);
			PasswordField passwordTextField = new PasswordField();
			root.add(passwordTextField, 1, 2);
			
			Button btn  = new Button();
			btn.setText("Sign In");
		
			HBox hBox = new HBox(10);
			hBox.setAlignment(Pos.BOTTOM_RIGHT);
			hBox.getChildren().add(btn); //这个API设置是什么意思？ 不能直接添加？
			final Text text = new Text();
			text.setId("warnText");
			root.add(text, 1, 6);
			btn.setOnAction(new EventHandler<ActionEvent>() {
				@Override
				public void handle(ActionEvent event) {
//					text.setFill(Color.FIREBRICK);
					String username = userTextField.getText();
					String passWord = passwordTextField.getText();
					text.setText("用户名为:"+username+"           密码为:"+passWord);
				}
			});
			root.add(hBox, 1,4);
			
			Scene scene = new Scene(root,500,600);
			URL resource = Main.class.getResource("login.css");
			String externalForm = resource.toExternalForm();
			scene.getStylesheets().add(externalForm);
			primaryStage.setTitle("我的第一个JAVAFX");
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		launch(args);
	}
}
